<script setup lang="ts">
import { getHitokoto } from '@/apis'

import { useTyped } from '@/hooks'
import { useRequest } from 'alova/client'

const oneWrodRef = ref<HTMLElement>()

useAnimate(oneWrodRef, [{ transform: 'scale(0)' }, { transform: 'scale(1)' }], 1000)

const oneWrodContentRef = ref<HTMLElement | null>(null)

const typedInstance = ref(null)

const { data, onSuccess, loading } = useRequest(getHitokoto)

onMounted(() => {
  onSuccess(() => {
    nextTick(() => {
      const { initTyped } = useTyped({
        instance: typedInstance,
        contentRef: oneWrodContentRef,
        content: data.value.hitokoto,
        options: {
          loop: false,
          cursorChar: ''
        }
      })

      initTyped()
    })
  })
})
</script>

<template>
  <div
    v-if="!loading"
    ref="oneWrodRef"
    class="one-wrod relative h-150px min-w-500px flex-col-center origin-center select-none overflow-hidden rounded-1 bg-origin-border backdrop-blur-sm"
  >
    <div class="flex">
      <div
        ref="oneWrodContentRef"
        class="text-16px"
      />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.one-wrod {
  box-shadow: 0 0 18px #ffffff80;

  &::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    content: '';
    background: #fff;
    filter: blur(5px);
    opacity: 0.3;
    z-index: -1;
  }

  &::before {
    content: '';
    position: absolute;
    inset: -20%;
    background: linear-gradient(
      45deg,
      rgba(255, 255, 255, 0) 40%,
      rgba(255, 255, 255, 0.7),
      rgba(255, 255, 255, 0) 60%
    );
    animation: shark-wrap 2s infinite;
    transform: translateX(-100%);
  }

  @keyframes shark-wrap {
    to {
      transform: translateX(100%);
    }
  }
}
</style>
